ATalk Server
Volume Number: 1
Issue Number: 10
Column Tag: C Workshop
"Dial a Fortune Apple Talk Server" 
By Robert B. Denny, Timothy T. Coad, Alisa Systems, Inc., MacTutor
Editorial Board
It's been about six months since the AppleTalk network was released. Yet there
seems to be little software available which uses this network. One reason is that the
market is too small as yet and developers can't see enough potential to risk the
investment. Another reason is that AppleTalk applications appear difficult to
implement, requiring a great deal of knowledge and understanding that is not easy to
obtain. Last, but certainly not least, Apple has failed to complete the basic services
that history has shown are required for successful introduction of a computer network.
About six or seven months ago, Apple released a publication called Inside
AppleTalk, available from the same source as Inside Macintosh. In addition, most
developers who subscribed to the Apple "Software Supplement" have received The
AppleTalk Manager: A Programmer's Guide, a part of Inside AppleTalk. These
documents do a fairly good job of describing the network architecture and the details of
using the AppleTalk services. If you have no experience with local area networks,
however, you may get lost in the jargon and fail to "see the forest through the trees".
This month's C Workshop is devoted to AppleTalk. It includes a complete server
application called Confucious which, when run on a Mac connected to the network,
provides a "guru" service. A Mac Pascal client application is described by Alan
Wootton in a separate article in this issue of Mac Tutor. The Pascal client, running on
another Mac, locates the C server and makes requests for pearls of wisdom, which the
server gladly sends back.
In order to keep this article's size reasonable, we assume that (1) you
understand how to use the Mac's I/O services and (2) you have access to (at least) the
AppleTalk Manager Programmer's Guide. The article describes the overall
architecture of the AppleTalk network, and concludes with a listing of the server's
code, written mostly in C. We'll look at programming details next month.
Fig. 1 - AppleTalk Components
NOTE: The descriptions given in this article are simplified so as to make it easier
to understand the overall architecture of AppleTalk. Please consult the Apple
documentation for full details.
Protocols and Layers
The lifeblood of any network is its suite of protocols that are used to negotiate
and communicate. Usually, there are two agents in a network operation, the client
and the server. The operation consists of a set of information exchanges between the
client and the server, according to a protocol.
In order to bring some order to the chaos that would be created by a multitude of
protocols, some of which are clients of other protocols and servers to yet others,
network designers use the concepts of layers and interfaces. A layer implements a set
of services via an interface. For example, the file system on the Mac has a layer that
handles "raw" disk I/O (the device manager), and a layer on top of that which handles
the organization of data on the disk into files and directories (the file manager). This
separation of functions makes it possible to handle both hard disks and floppies with
the same file manager routines. The file manager uses a defined interface to the device
manager for its requests. Finally, the organization of data on the disk as files and
directories is a sort of "spatial protocol".
Network architectures are normally divided into seven layers, according to the
ISO "Open Systems Interconnection" convention adopted about five years ago. These
layers, from lowest to highest are:
Physical: Electrical and mechanical aspects of communication circuits.
Data Link: Data and frame formats, bus access & contention protocols, error
detection, other low level link services.
Network: Addressing and routing of messages between "sockets
transparently across multiple data links.
Transport: Error and flow control between sockets. Exchanges of information
between routing agents on special sockets.
Session: Opening and closing logical links between sockets. Starting up
remote servers on request. Naming of entities and name services.
Presentation: Crypto systems, code conversion (e.g., ASCII to EBCDIC), other
transformations needed for the native application environment.
Application: Protocols used between specific applications.
AppleTalk Architecture
Apple Computer has so far defined and published protocols for the physical
through the transport layers of AppleTalk. Generally speaking, AppleTalk has a bus
oriented, packet-based architecture, supporting internetworking, named objects,
adaptive routing and a transaction-oriented transport service.
Services are implemented in a pair of I/O drivers and associated resources which
are opened permanently on 512K Macs, and live in the system heap. On 128K Macs,
applications which want to use the network must manually open the drivers, loading
them into the application heap. This means that no "detached" service processes in the
system heap can be supported on the smaller systems. Figure 1 shows the breakdown
of AppleTalk functions and the drivers that implement them.
Physical & Data Link Layers: ALAP
The physical layer consists of a bus topology twisted-pair cable carrying
electrical signals conforming to the EIA RS-422 standard. The Mac hardware has a
"serial communications controller" (SCC) which is capable of being software
configured as a standard async or sync port, or as an AppleTalk port. AppleTalk uses
the printer port on the Mac.
The data link layer is implemented in software and uses the "AppleTalk Link
Access Protocol" (ALAP) to manage usage of the common bus and to detect transmission
errors between physically connected Mac systems. ALAP uses a frame format which is
similar to that used by several well known block-oriented protocols such as HDLC.
The algorithms used to manage multiple access to the bus are specific to AppleTalk, and
fall into the category of "Carrier Sense Multiple Access" (CSMA).
Simply stated, the rules of CSMA are: (1) talk if no one else is talking; (2) if
you want to talk and some one else is already talking, go away and try again later; (3)
if two of you start talking at the same time, yell "Abort!" so everyone else knows, then
both of you go away and try again later.
One other thing to note: The assignment of node numbers to each station on a
network is not done by the user. Rather, the ALAP software tries to assign a random
node number when the Mac is booted, then shouts it out over the net. If no one else
objects, that is the node number to be used. Otherwise, another try is made.As an
application developer, you'll rarely deal directly with ALAP.
Network Layer: DDP
The network layer uses the "Datagram Delivery Protocol" (DDP), which defines
the format of the address header which is included in each packet and which stays with
the packet between cooperating processes through communication endpoints called
sockets. The path between sockets may span several physical links, and may go through
intermediate systems. One Mac may have several AppleTalk connections open at a time,
so the node number is not enough to identify a network address.
An address must consist of at least a node number and a socket number. In fact,
AppleTalk considers a socket to be the one and only network-visible entity. Socket
numbers fall into two groups. The "well-known" sockets (1-127) are assigned by
Apple for specific generic network services and experimentation. The others
(128-254) are called "dynamic" sockets. They are assigned temporarily and are
often associated with a name managed by the Name Binding service of AppleTalk (see
below).
Individual AppleTalk networks may be tied together to form an internetwork.
Node numbers are unique only within a single physical network, so DDP requires that
each network be assigned a network number. Figure 2 (see top of next page) shows a
three-net internetwork. The Networks are connected by either a full bridge or a pair
of half-bridges. The full bridge attaches directly to two physical networks and